<html>
<head><meta charset="utf-8"><title>Style convention for irrefutable patterns · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html">Style convention for irrefutable patterns</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="239654519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239654519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239654519">(May 20 2021 at 20:30)</a>:</h4>
<p>I was looking at this code that I wrote in the past:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">    </span><span class="k">fn</span> <span class="nf">from_residual</span><span class="p">(</span><span class="n">residual</span>: <span class="nb">Result</span><span class="o">&lt;</span><span class="n">convert</span>::<span class="n">Infallible</span><span class="p">,</span><span class="w"> </span><span class="n">E</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">match</span><span class="w"> </span><span class="n">residual</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="nb">Err</span><span class="p">(</span><span class="n">e</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="nb">Err</span><span class="p">(</span><span class="nb">From</span>::<span class="n">from</span><span class="p">(</span><span class="n">e</span><span class="p">)),</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>And thinking that perhaps I should rewrite it to</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">    </span><span class="k">fn</span> <span class="nf">from_residual</span><span class="p">(</span><span class="n">residual</span>: <span class="nb">Result</span><span class="o">&lt;</span><span class="n">convert</span>::<span class="n">Infallible</span><span class="p">,</span><span class="w"> </span><span class="n">E</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="nb">Err</span><span class="p">(</span><span class="n">e</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">residual</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="nb">Err</span><span class="p">(</span><span class="nb">From</span>::<span class="n">from</span><span class="p">(</span><span class="n">e</span><span class="p">))</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>But that made me think that I could go even further to</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">    </span><span class="k">fn</span> <span class="nf">from_residual</span><span class="p">(</span><span class="nb">Err</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>: <span class="nb">Result</span><span class="o">&lt;</span><span class="n">convert</span>::<span class="n">Infallible</span><span class="p">,</span><span class="w"> </span><span class="n">E</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="nb">Err</span><span class="p">(</span><span class="nb">From</span>::<span class="n">from</span><span class="p">(</span><span class="n">e</span><span class="p">))</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Do we have any style conventions for which of these three options are the best way to write this in the library?</p>
<p>(It's a trait impl, so the pattern in the parameter is potentially tolerable here in a way that it wouldn't be in something that'll show more directly in rustdoc.)</p>



<a name="239655246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239655246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239655246">(May 20 2021 at 20:34)</a>:</h4>
<p>I always struggle a bit with uninhabited patterns being just... not there, when skimming, but I don't think we have any guidelines yet</p>



<a name="239655304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239655304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239655304">(May 20 2021 at 20:35)</a>:</h4>
<p>Option 3 seems like it most clearly communicates that there's only one form though, for the purposes of the function.</p>



<a name="239655527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239655527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239655527">(May 20 2021 at 20:36)</a>:</h4>
<p>I usually don't care for patterns in function headers, but for the specific case of Infallible, I find that really appealing.</p>



<a name="239655568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239655568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239655568">(May 20 2021 at 20:37)</a>:</h4>
<p>Because it's <em>semantically</em> just an error, and only <em>structurally</em> a Result.</p>



<a name="239656124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239656124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239656124">(May 20 2021 at 20:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns/near/239655304">said</a>:</p>
<blockquote>
<p>Option 3 seems like it most clearly communicates that there's only one form though, for the purposes of the function.</p>
</blockquote>
<p>interesting. I had the opposite reaction, and feel like option 3 is the least readable. My preference order was 2 &gt; 1 &gt; 3.</p>



<a name="239656155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239656155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239656155">(May 20 2021 at 20:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns/near/239655568">said</a>:</p>
<blockquote>
<p>Because it's <em>semantically</em> just an error, and only <em>structurally</em> a Result.</p>
</blockquote>
<p>this swayed me a bit though</p>



<a name="239656320"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239656320" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239656320">(May 20 2021 at 20:42)</a>:</h4>
<p>I do generally feel like patterns in function args is generally distracting and harder to read. I feel like it's uncommon and not what my brain is looking for when scanning for function definitions.</p>



<a name="239656510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239656510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239656510">(May 20 2021 at 20:44)</a>:</h4>
<p>though I expect it wouldn't be particularly hard to acclimate myself to them, and that I'd quickly not feel the same way</p>



<a name="239656611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239656611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239656611">(May 20 2021 at 20:45)</a>:</h4>
<p><code>!</code> in the signature would make it more obvious that there's something uncommon going on.</p>



<a name="239656612"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239656612" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239656612">(May 20 2021 at 20:45)</a>:</h4>
<p>Either way though I don't think there's a substantial difference between these versions, certainly not enough to justify documenting a style convention (not that this was suggested)</p>



<a name="239656779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239656779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239656779">(May 20 2021 at 20:46)</a>:</h4>
<p>isn't it documented somewhere that the use of <code>match</code> is the idiom for Rust?</p>



<a name="239657004"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239657004" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239657004">(May 20 2021 at 20:48)</a>:</h4>
<p>I also would find an <code>.unwrap_infallible()</code> appealing.</p>



<a name="239658746"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239658746" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239658746">(May 20 2021 at 21:02)</a>:</h4>
<p><span class="user-mention silent" data-user-id="281739">oliver</span> <a href="#narrow/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns/near/239656779">said</a>:</p>
<blockquote>
<p>isn't it documented somewhere that the use of <code>match</code> is the idiom for Rust?</p>
</blockquote>
<p>this was a dream I had apparently, there is nothing written in docs I can find suggesting <code>match</code> over anything else</p>



<a name="239659012"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239659012" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239659012">(May 20 2021 at 21:04)</a>:</h4>
<p>there are a lot of times that <code>if let</code> looks nicer than a <code>match</code>, and here that naturally becomes an irrefutable <code>let</code></p>



<a name="239659094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239659094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239659094">(May 20 2021 at 21:05)</a>:</h4>
<p>I could give or take parameter patterns, but single-pattern <code>match</code> is distasteful to me</p>



<a name="239659620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239659620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239659620">(May 20 2021 at 21:08)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns/near/239657004">said</a>:</p>
<blockquote>
<p>I also would find an <code>.unwrap_infallible()</code> appealing.</p>
</blockquote>
<p>Option 4, using <a href="https://doc.rust-lang.org/nightly/std/result/enum.Result.html#method.into_err">https://doc.rust-lang.org/nightly/std/result/enum.Result.html#method.into_err</a> (<code>#![feature(unwrap_infallible)]</code>)</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">    </span><span class="k">fn</span> <span class="nf">from_residual</span><span class="p">(</span><span class="n">r</span>: <span class="nb">Result</span><span class="o">&lt;</span><span class="n">convert</span>::<span class="n">Infallible</span><span class="p">,</span><span class="w"> </span><span class="n">E</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="nb">Err</span><span class="p">(</span><span class="nb">From</span>::<span class="n">from</span><span class="p">(</span><span class="n">r</span><span class="p">.</span><span class="n">into_err</span><span class="p">()))</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="239659731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239659731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239659731">(May 20 2021 at 21:09)</a>:</h4>
<p>Hm. I'm not sure I find that as clear, though I guess it might be something I get used to. infallible_err or something would be clearer, I think; into_err doesn't sound like it is <em>only</em> for infallible</p>



<a name="239659967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239659967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239659967">(May 20 2021 at 21:11)</a>:</h4>
<p>Lots of conversation about the name for that method <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span> <code>always_ok</code> is another one, from &lt;<a href="https://github.com/rust-lang/rfcs/issues/1723">https://github.com/rust-lang/rfcs/issues/1723</a>&gt;.</p>



<a name="239660072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239660072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239660072">(May 20 2021 at 21:11)</a>:</h4>
<p>Yeah, I'm sure.</p>



<a name="239785677"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239785677" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239785677">(May 21 2021 at 17:27)</a>:</h4>
<p><span class="user-mention silent" data-user-id="138448">cuviper</span> <a href="#narrow/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns/near/239659094">said</a>:</p>
<blockquote>
<p>I could give or take parameter patterns, but single-pattern <code>match</code> is distasteful to me</p>
</blockquote>
<p>I like it because it really clearly highlights that one of the variants is uninhabited, and otherwise looks the same as other interactions with Result which usually use match</p>



<a name="239785879"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239785879" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239785879">(May 21 2021 at 17:29)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns/near/239659620">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns/near/239657004">said</a>:</p>
<blockquote>
<p>I also would find an <code>.unwrap_infallible()</code> appealing.</p>
</blockquote>
<p>Option 4, using <a href="https://doc.rust-lang.org/nightly/std/result/enum.Result.html#method.into_err">https://doc.rust-lang.org/nightly/std/result/enum.Result.html#method.into_err</a> (<code>#![feature(unwrap_infallible)]</code>)</p>
<p><div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">    </span><span class="k">fn</span> <span class="nf">from_residual</span><span class="p">(</span><span class="n">r</span>: <span class="nb">Result</span><span class="o">&lt;</span><span class="n">convert</span>::<span class="n">Infallible</span><span class="p">,</span><span class="w"> </span><span class="n">E</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="nb">Err</span><span class="p">(</span><span class="nb">From</span>::<span class="n">from</span><span class="p">(</span><span class="n">r</span><span class="p">.</span><span class="n">into_err</span><span class="p">()))</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
</code></pre></div><br>
</p>
</blockquote>
<p>fancy</p>



<a name="239785910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239785910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239785910">(May 21 2021 at 17:29)</a>:</h4>
<p>is there a way to search for types that implement <code>From&lt;!&gt;</code></p>



<a name="239785929"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239785929" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239785929">(May 21 2021 at 17:29)</a>:</h4>
<p>other than searching the codebase</p>



<a name="239785939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239785939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239785939">(May 21 2021 at 17:29)</a>:</h4>
<p>ill just search the codebase</p>



<a name="239786356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239786356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239786356">(May 21 2021 at 17:32)</a>:</h4>
<p>wait no i got confused, that's not the right reflexive impl</p>



<a name="239786383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239786383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jane Lusby <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239786383">(May 21 2021 at 17:32)</a>:</h4>
<p>how do I even find what types impl <code>Into&lt;!&gt;</code>, gah</p>



<a name="239889239"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239889239" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239889239">(May 22 2021 at 17:57)</a>:</h4>
<p>I do love both the pattern context in argument lists, as well as that <code>!</code> makes refutable patterns irrefutable, allowing match -&gt; let. However they're both semi-obscure features, and I tend to avoid using semi-obscure features together, so as to not compound the obscurity.</p>



<a name="239889482"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/Style%20convention%20for%20irrefutable%20patterns/near/239889482" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/Style.20convention.20for.20irrefutable.20patterns.html#239889482">(May 22 2021 at 18:01)</a>:</h4>
<p>Yeah, notably this only works because libcore has <code>exhaustive_patterns</code> enabled.</p>
<p>Without that, it has to be </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">    </span><span class="k">fn</span> <span class="nf">from_residual</span><span class="p">(</span><span class="n">residual</span>: <span class="nb">Result</span><span class="o">&lt;</span><span class="n">convert</span>::<span class="n">Infallible</span><span class="p">,</span><span class="w"> </span><span class="n">E</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">match</span><span class="w"> </span><span class="n">residual</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="nb">Ok</span><span class="p">(</span><span class="n">never</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="k">match</span><span class="w"> </span><span class="n">never</span><span class="w"> </span><span class="p">{},</span><span class="w"></span>
<span class="w">            </span><span class="nb">Err</span><span class="p">(</span><span class="n">e</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="nb">Err</span><span class="p">(</span><span class="nb">From</span>::<span class="n">from</span><span class="p">(</span><span class="n">e</span><span class="p">)),</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>(Example: <a href="https://github.com/SergioBenitez/Rocket/blob/08e5b6dd0dd9d723ca2bd4488ff4a9ef0af8b91b/core/lib/src/outcome.rs#L615-L623">https://github.com/SergioBenitez/Rocket/blob/08e5b6dd0dd9d723ca2bd4488ff4a9ef0af8b91b/core/lib/src/outcome.rs#L615-L623</a> )</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>